<template>
	<view style="background: #f1f1f1;min-height: 100vh;">

		<tn-sticky>
			<view class=""
				style="display: flex;justify-content: space-between;padding: 10rpx 30rpx;font-size: 28rpx;color: #000;background: #f1f1f1;">
				<view class=""> 共 {{total}}件商品 </view>
				<view class="" @click="edit(0)" v-if="current==1" style="color: #e9b461;">编辑</view>
				<view class="" @click="edit(1)" v-else>取消</view>
			</view>
		</tn-sticky>
		<view class="" style="background: #fff;margin: 20rpx;padding: 17rpx 20rpx;border-radius: 8rpx;display: flex;"
			v-for="(item,index) in dataList" :key="index" @click.stop="order(item)">
			<view class="" style="display: flex;align-items: center;margin-right: 20rpx"
				@click.stop="currentItem(item,index)" v-if="current==0">
				<image src="https://oss.taoding1688.com/static/uniapp/static/commission/radiob.png" mode="widthFix" style="width: 40rpx;height: 40rpx;"
					v-if="item.disbeld==true"></image>
				<image src="https://oss.taoding1688.com/static/uniapp/static/commission/radio.png" mode="widthFix" style="width: 40rpx;height: 40rpx;"
					v-else></image>
			</view>
			<image :src="info.app.cdnurl+item.goods.image" mode="widthFix" style="width: 160rpx;height: 160rpx;">
			</image>
			<view class=""
				style="display: flex;flex-direction: column;justify-content: space-around;font-size: 28rpx;margin-left: 20rpx;">
				<view class="" style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis;width: 300rpx;">
					{{item.goods.title}}
				</view>
				<view class=""
					style="color: #999999;font-size: 26rpx;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;width: 400rpx;">
					{{item.goods.subtitle}}
				</view>
				<view class="" style="color: rgb(255, 48, 0);">￥{{item.goods.price[0]}}</view>
			</view>
		</view>
		<view class=""
			style="position: fixed;bottom: 0;height: 100rpx;background: #fff;width: 100%;z-index: 999;display: flex;align-items: center;justify-content: space-between;padding: 0 50rpx;"
			v-if="current==0">
			<view class="" style="display: flex;" @click="">
				<image src="https://oss.taoding1688.com/static/uniapp/static/commission/radio.png" mode="widthFix" style="width: 40rpx;height: 40rpx;"
					@click="selectChange(0)" v-if="selectCurrent==1"></image>
				<image src="https://oss.taoding1688.com/static/uniapp/static/commission/radiob.png" mode="widthFix" style="width: 40rpx;height: 40rpx;"
					@click="selectChange(1)" v-if="selectCurrent==0"></image>
				<view class="" style="font-size: 26rpx;margin-left: 10rpx;">全选</view>
			</view>
			<view class="">
				<view class="" style="background: #e9b461;color: #fff;padding: 18rpx 40rpx;border-radius: 50rpx;"
					@click="delFootprint">删除足迹
				</view>
			</view>
		</view>
		<view class="" style="height: 30rpx;"></view>
		<tn-load-more status="nomore" style="padding: 20rpx 0;"></tn-load-more>
		<view class="" style="height: 30rpx;"></view>
		
		
		    <tn-modal v-model="show" :title="title" :content="content" :button="button"></tn-modal>

	</view>
</template>

<script>
	import {
		getUserGoodsLog,
		getGoodsLogViewDely
	} from "@/apis"
	export default {
		data() {
			return {
				total:'',
				selectCurrent: 1,
				current: 1,
				obj: {
					list_rows: 10,
					page: 1,
					type: 'views'
				},
				last_page: '',
				dataList: [],
				show: false,
				        title: '提示信息',
				        content: '提示信息的内容',
				        button: [{
				            text: '取消',
				            backgroundColor: '#a4e82f',
				            fontColor: '#000',
				            plain: true,
				            shape: 'round'
				          },
				          {
				            text: '确定',
				            backgroundColor: 'tn-bg-indigo',
				            fontColor: '#FFFFFF'
				          }
				        ]

			}
		},
		async onLoad() {
			let res = await getUserGoodsLog(this.obj)
			this.total=res.data.total
			let arr = res.data.data
			this.dataList = arr.map(item => {
				item.disbeld = false
				return item
			})
			this.last_page = res.data.last_page
		},
		methods: {
			edit(index) {
				this.current = index
			},
			currentItem(item, index) {
				if (this.dataList[index].disbeld == true) {
					this.dataList[index].disbeld = false
					this.selectCurrent = 1
				} else {
					this.dataList[index].disbeld = true
				}
				
				let boo = this.dataList.every(obj => obj.disbeld == true);
				let str = this.dataList.some(obj => obj.disbeld == true);
				if (boo) {
					this.selectCurrent = 0
				}
				if (str == false) {
					this.selectCurrent = 1
				}
			},
			order(item){
				uni.navigateTo({
					url:'/templatePage/productDetail/productDetail?index='+item.goods_id
				})
			},
			selectChange(index) {
				this.selectCurrent = index




				if (index == 0) {
					this.dataList = this.dataList.map(item => {
						item.disbeld = true
						return item
					})
					// return

				}
				if (index == 1) {
					this.dataList = this.dataList.map(item => {
						item.disbeld = false
						return item
					})
				}


			},
			async delFootprint() {
				const trueIds = [];
				this.dataList.forEach(obj => {
					if (obj.disbeld == true) {
						trueIds.push(obj.goods_id);
					}
				});
				if (trueIds.length>0) {
					// this.show = true;
					
					
					
					let res=await getGoodsLogViewDely(trueIds.join(','))
					
					let arrs = await getUserGoodsLog(this.obj)
					let arr = arrs.data.data
					this.obj.page=1
					this.dataList = arr.map(item => {
						item.disbeld = false
						return item
					})
					this.last_page = arrs.data.last_page
				}
				
			}
		},

		onReachBottom() {
			if (this.obj.page < this.last_page) {
				this.obj.page++
				getUserGoodsLog(this.obj).then(res => {
					let arr = res.data.data
					this.dataList = this.dataList.concat(arr.map(item => {
						item.disbeld = false
						return item
					}))
				})
			}
		}
	}
</script>

<style>

</style>